package com.ly.ocw.service.weixin;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springside.modules.mapper.JsonMapper;

import com.ly.ocw.rest.dto.HzwTokenDto;
import com.ly.ocw.utils.HttpUtil;

/**
 * 
 * 从hzw中控服务器读取accessToken等数据
 * @author Peter
 */
// Spring Service Bean的标识.
@Component
public class WeixinApiTokenService {

	@Value("${hzwTokenCenterUrl}")
	private String hzwTokenCenterUrl;

	public String getHzwTokenCenterUrl() {
		return hzwTokenCenterUrl;
	}

	public void setHzwTokenCenterUrl(String hzwTokenCenterUrl) {
		this.hzwTokenCenterUrl = hzwTokenCenterUrl;
	}

	private static JsonMapper mapper = JsonMapper.nonDefaultMapper();

	public String getAccessToken() {
		String resp = HttpUtil.httpGet(hzwTokenCenterUrl);

		HzwTokenDto bean = mapper.fromJson(resp, HzwTokenDto.class);
		return bean.getAccessToken();
	}

	public String getApiTicket() {
		String resp = HttpUtil.httpGet(hzwTokenCenterUrl);

		HzwTokenDto bean = mapper.fromJson(resp, HzwTokenDto.class);
		return bean.getAPI_TICKET();
	}

	public String getJsApiTicket() {
		String resp = HttpUtil.httpGet(hzwTokenCenterUrl);

		HzwTokenDto bean = mapper.fromJson(resp, HzwTokenDto.class);
		return bean.getJS_API_TICKET();
	}

	public static void main(String[] args) {
		/*String resp = HttpUtil.httpGet(hzwTokenCenterUrl);
		HzwTokenDto bean = mapper.fromJson(resp, HzwTokenDto.class);

		System.out.println(bean.getAccessToken());
		System.out.println(bean.getAPI_TICKET());
		System.out.println(bean.getJS_API_TICKET());*/
	}
}
